#ifndef RSDLOADPKG_H
#define RSDLOADPKG_H

#include "protocol.h"
#include "client.h"
#include "serverfile.h"
#include "lzhl.h"

class CChecksumList;

class RSDownloadPackage : public Protocol
{
	public:
		RSDownloadPackage(Client*);
		virtual ~RSDownloadPackage();

		virtual bool8 recognize(uint8* Msg, uint32 Len);
		virtual int32 start(uint8* Msg, uint32 Len);

		virtual void netIn(int32 Amt);
		virtual void netOut(int32 Amt);

		virtual void fileIn(int32 Amt);
		virtual void fileEOF();
		virtual void fileErr(uint32 Err);       // kharmon.  04-05-07.  #19307.  Change argument to uint32 so that it overrides base class version.

	protected:
		int32 CompressPacket(uint8 *buf, int32 bufsize);
		void receiveChecksums(uint8 *buffer, uint32 len);

		void BeginRsync();

		void InitState();

	protected:
		enum { PACKETSIZE=256 };

		bool8 SendRSyncBlock();
		int32 Digest(uint32 amount);
		void sendQueued();

	protected:
		uint32	m_rsync_read;

		uint8	m_rsyncbuffer[CServerFile::BLOCK_SIZE + PACKETSIZE];

		int32	m_state;
		int32	m_current_block;

		bool8	m_end_of_file;
		String 	m_filename;

		uint32	m_resumesize;

		CServerFile m_serverfile;

		LZHL_CHANDLE m_compressor;

		uint8 *m_compressed_buffer;
		int32 m_cbqueued;

		bool8 m_send_queued;
		bool8 m_multibyte;
};

#endif
